package com.quik.system.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.quik.common.Constants;
import com.quik.entity.SysAccount;

/**
 * 功能说明：
 *        登录控制
 * @author Jenny
 *
 */
public class FrontLoginFilter extends HandlerInterceptorAdapter{
	private static final Logger LOG = Logger.getLogger(FrontLoginFilter.class);
	
	private static final String LOGIN_URL = "/login/init";

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception{
		SysAccount account = (SysAccount)request.getSession().getAttribute(Constants.SESSION_ACCOUNT);
		if (account == null) {
			LOG.debug("-------session not fond!--------");
					
			response.sendRedirect(request.getContextPath() + LOGIN_URL);
			return false;
		} else {
			return true;
		}
	}
}
